<?php
/**
 * Created by PhpStorm.
 * User: LiuJiaJun
 * Date: 2019/3/31
 * Time: 12:48
 */

namespace api\storage\common;


use api\storage\exception\BaseException;
use Exception;
use service\logger\LoggerFactory;
use think\exception\Handle;

class HttpExceptionHandler extends Handle
{

    public function render(Exception $e)
    {
        if (APP_DEBUG == true && !($e instanceof BaseException) ) {
            return parent::render($e);
        } elseif ($e instanceof BaseException) {
            $msg = $e->getMessage();
            $logger = LoggerFactory::getLogger('exception');
            $logger->info($e->getTraceAsString());
        } else {
            $msg = '系统错误！';
        }
        $code = 100;
        $httpCode = 500;
        $result = [
            'code' => $code,
            'msg' => $msg,
            'data' => [],
        ];
        return json($result, $httpCode);
    }
}